from flask_socketio import join_room, leave_room

from commonService.socketService import socketService


class signallingService:


    def enterRoom(self,userId,roomId):
        #加入房间
        join_room(roomId)
        # 发送给自己joined信令
        socketService.send_to_self(socketService.SING_JOINED, userId)
        # 发送给其他用户other_join信令
        socketService.send_to_other(socketService.SING_OTHER_JOINED, roomId, userId)


    def leaveRoom(self, sid, roomId):
        #离开房间
        leave_room(roomId);
        #发给自己已离开信令
        socketService.send_to_self(socketService.SING_LEAVED,"you have leaved")
        #发送给别人离开信令
        socketService.send_to_other(socketService.SING_OTHER_LEAVE,roomId,sid)

    def transferMsg(self, roomId, data):
        socketService.send_to_other(socketService.SING_MESSAGE,roomId,data)
